<?php
session_start();
include_once("../service/userService.php");
include_once("../util/constant.php");

$userId = $_SESSION["username"][0];
$fullName = $_POST["fullName"];
$address = $_POST["profileAddress"];
$gender = $_POST["gender"];

if(isset($_POST["changePassMode"])){
	$mode = $_POST["changePassMode"];
	$newPassword = $_POST["newPassword"];
	if(changePassword($userId, md5($newPassword))){
		echo "<script>window.location.href = '../profile-cart.php?action=".UPDATE_SUCCESSFULLY.".2#profile-tab';</script>";
	} else {
		echo "<script>window.location.href = '../profile-cart.php?action=".UPDATE_FAILED.".2#profile-tab';</script>";
	}
} else {
	if(editProfile($userId, $fullName, $address, $gender)){
		echo "<script>window.location.href = '../profile-cart.php?action=".UPDATE_SUCCESSFULLY.".1#profile-tab';</script>";
	} else {
		echo "<script>window.location.href = '../profile-cart.php?action=".UPDATE_FAILED.".1#profile-tab';</script>";
	}
	
}

?>